import {observable, action} from 'mobx';
import * as API from '../../api/calendar'
import { BrowserHrm } from 'weaver-mobile-page'

export default class CalendarStore {

  @observable calendarInfo = '';
  @observable starteDate = '';
  @observable endDate = '';
  @observable calendarList = '';
  @observable selectdate = '';
  @observable meetingType = '';
  @observable selectUserId = '';
  @observable weekStartDay = 0;
  //目的:日历组件不是受控组件,只有在第一次渲染的时候才有效果,第一次render的时候没有走接口取得正常的值,所以加这个来进行判断
  @observable isInit= false;
  @observable calendarTabPath = {
    0:'/calendar/allMeeting',
    1:'/calendar/endMeeting',
    2:'/calendar/goingMeeting',
    3:'/calendar/notStartMeeting'
  };
  @observable hrmBrowser = new BrowserHrm.Store({route: '/calendar/allMeeting',id:'singleHrm'});
  @observable hrmBrowserTabs = {
    allMeeting: new BrowserHrm.Store({route: '/calendar/allMeeting',id:'singleHrm'}),
    endMeeting: new BrowserHrm.Store({route: '/calendar/endMeeting',id:'singleHrm'}),
    goingMeeting: new BrowserHrm.Store({route: '/calendar/goingMeeting',id:'singleHrm'}),
    notStartMeeting: new BrowserHrm.Store({route: '/calendar/notStartMeeting',id:'singleHrm'}),
  };
  @observable roomUsedSelectDate = '';
  @observable hrmBrowserLoading = false;
  @action
  setState = (params = {}) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
  }

  @action
  getCalendarInfo = (params) => {
    const {isCalendar} = {...params}
    API.getCalendarInfo(params).then((result) => {
      if(result.mobileEvents){
        isCalendar === '1'?(this.calendarInfo = result.mobileEvents, this.weekStartDay = result.weekStartDay):this.calendarList = result.mobileEvents
        if(!this.isInit){
          isCalendar === '1'?this.isInit = true:'';
        }
      }
    })
  }

  @action
  setHrmBrowserRoute = (params) => {
    if(params){
      this.hrmBrowser = new BrowserHrm.Store({route: `${params}`,id:'singleHrm'});
    }else{
      this.hrmBrowser = new BrowserHrm.Store({route: '/calendar/allMeeting',id:'singleHrm'});
    }
  }
}